
#include "log.h"

#include "f32file.h"
#include <EIKENV.H>


RLog* RLog::NewL()
    {
    RLog* self = NewLC();
    CleanupStack::Pop(self);
    return self;
    }
    
RLog* RLog::NewLC()
    {
    RLog* self = new (ELeave) RLog();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

RLog::RLog()
    {
    }

RLog::~RLog()
    {
    }

void RLog::ConstructL()
    {
    }
 

void RLog::Log(const TDesC8& aErrMsg)
{
	_LIT(KLogPath, "c:\\data\\logdir\\log.txt");
	//����
	RFile file;
	//open file for write
	TInt result = file.Open(CEikonEnv::Static()->FsSession(), KLogPath,  EFileWrite);
	if(result == KErrNone)
	{
		TInt fileSize;
		file.Size(fileSize);

		file.Seek(ESeekEnd,fileSize);
		file.Write(_L8("\r\n"));
		file.Write(aErrMsg);
		file.Close();
	}
}


void RLog::Log(const TDesC8 & aErrMsg, const TInt aErrCode)
{
	HBufC8 * buf = HBufC8::New(aErrMsg.Length() + 20);
	buf->Des().Copy(aErrMsg);
	buf->Des().Append(_L8(":"));
	buf->Des().AppendNum(aErrCode);
	Log(*buf);
	delete buf;
}

void RLog::Log(const TDesC8 & aErrTypeName, const TDesC8& aErrMsg)
{
	HBufC8* buf=HBufC8::New(aErrTypeName.Length()+2+aErrMsg.Length());
	buf->Des().Copy(aErrTypeName);
	buf->Des().Append(_L8(":"));
	buf->Des().Append(aErrMsg);
	Log(*buf);
	delete buf;
}

